package com.avoid.easymqtt.remoting.netty;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 描述
 *
 * @author avoid@fiture.com
 * @date 2022/4/29
 * @motto Life is so short,do something to make yourself happy,such as coding
 */
public class NettyThreadFactory implements ThreadFactory {
    private final String threadName;

    private final AtomicInteger threadIndex = new AtomicInteger(0);

    public NettyThreadFactory(String threadName) {
        this.threadName = threadName;
    }

    @Override
    public Thread newThread(Runnable r) {
        return new Thread(r, String.format(threadName + "_%d", this.threadIndex.incrementAndGet()));

    }
}
